package com.fengmi.controller;

import com.fengmi.entity.MallGoodsSpec;
import com.fengmi.entity.MallGoodsSpecOptions;
import com.fengmi.service.MallGoodsSpecOptionsService;
import com.fengmi.vo.InfoResult;
import com.fengmi.vo.PageResult;
import com.fengmi.vo.SpecOptionsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author: 施俊豪
 * Date: 2022/1/19 10:22
 * Note: 产品规格控制器
 */
@Api(description = "产品规格API")
@CrossOrigin
@RequestMapping("/spec")
@RestController
public class MallGoodsSpecController {

    @Autowired
    private MallGoodsSpecOptionsService mallGoodsSpecOptionsService;

    @ApiOperation("产品规格和选项分页+条件查询API")
    @RequestMapping("/findSpecAndOptions")
    public PageResult<MallGoodsSpecOptions> findSpecAndOptions(@ApiParam("查询条件") @RequestBody MallGoodsSpecOptions options,
                                                               @ApiParam("当前页数")@RequestParam(value="pageNum",defaultValue = "1")String pageNum,
                                                               @ApiParam("当前页记录数")@RequestParam(value = "pageSize", defaultValue = "5") String pageSize,
                                                               @RequestHeader("token")String token){
        System.out.println("查询产品规格和选项的token=====>"+token);
        return mallGoodsSpecOptionsService.findSpecAndOptions(options, pageNum, pageSize);
    }

    @ApiOperation("添加商品规格和选项的API")
    @RequestMapping("addSpecAndOptions")
    public InfoResult addSpecAndOptions(@ApiParam("添加参数") @RequestBody MallGoodsSpec spec,
                                        @RequestHeader("token")String token){
        System.out.println("添加方法token"+token);
        return mallGoodsSpecOptionsService.addSpecAndOptions(spec);
    }

    @ApiOperation("修改商品规格选项API")
    @PutMapping("/updateSpecOptions")
    public InfoResult updateSpecOptions(@ApiParam("修改信息")@RequestBody MallGoodsSpecOptions options,
                                        @RequestHeader("token")String token){
        System.out.println("修改方法token:"+token);
        return mallGoodsSpecOptionsService.updateSpecOptions(options);
    }

    @ApiOperation("删除商品规格选项和商品规格API")
    @DeleteMapping("/deleteSpecOptions")
    public InfoResult deleteSpecOptions(@ApiParam("删除数据") @RequestBody MallGoodsSpecOptions options,
                                       @RequestHeader("token")String token){
        System.out.println("删除方法token:"+token);
        return mallGoodsSpecOptionsService.delSepcAndOptions(options);
    }

    @ApiOperation("查询所有商品规格")
    @RequestMapping("/findAllSpec")
    public InfoResult findAllSpec(@RequestHeader("token")String token){
        System.out.println("查询所有商品规格的token:"+token);
        return mallGoodsSpecOptionsService.findSpecAll();
    }

    @ApiOperation("批量删除商品规格选项和商品规格API")
    @DeleteMapping("/delBathSpecAndOptions")
    public InfoResult delBathSpecAndOptions(@ApiParam("删除数据") @RequestBody SpecOptionsVO specOptionsVO,
                                       @RequestHeader("token")String token){
        System.out.println("删除方法token:"+token);
        return mallGoodsSpecOptionsService.removeSpecAndOptions(specOptionsVO);
    }

    /**
     * @Note : 根据商品模板id查询商品规格信息
     * @Date : 2022-02-04 16:11:19
     * @Author : 清酒吖
    */ 
    @RequestMapping("findSpecAndOptions/{templateId}")
    public List<MallGoodsSpec> findSpecAndOptions(@PathVariable String templateId){
        return mallGoodsSpecOptionsService.findSpecAndOptionsByTemplateId(templateId);
    }
}
